<!DOCTYPE HTML>
<html lang="">
<head>
    <title>订单详情</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <!-- jquery -->
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css"  href="/bootstrap/css/bootstrap.min.css"/>
    <script type="text/javascript" src="/bootstrap/js/bootstrap.min.js">
    </script>
    <!-- layer -->
    <script type="text/javascript" src="/layer/layer.js"></script>
    <!-- common.js -->
    <script type="text/javascript" src="/js/common.js"></script>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-heading">秒杀订单详情</div>
    <table class="table" id="order">
        <tr>
            <td>商品名称</td>
            <td id="goodsName" colspan="3"></td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td colspan="2">
                <img id="goodsImage" width="200" height="200" alt=""/>
            </td>
        </tr>
        <tr>
            <td>订单价格</td>
            <td colspan="2" id="order.goodsPrice"></td>
        </tr>
        <tr>
            <td>下单时间</td>
            <td id="createTime" colspan="2"></td>
        </tr>
        <tr>
            <td>订单状态</td>
            <td id="status">
<!--                <span>未支付</span>-->
<!--                <span>待发货</span>-->
<!--                <span>已发货</span>-->
<!--                <span>已收货</span>-->
<!--                <span>已退款</span>-->
<!--                <span>已完成</span>-->
            </td>
            <td>
                <button class="btn btn-primary btn-block" type="submit" id="payButton">
                    立即支付
                </button>
            </td>
        </tr>
        <tr>
            <td>收货人</td>
            <td colspan="2">XXX 18012345678</td>
        </tr>
        <tr>
            <td>收货地址</td>
            <td colspan="2">上海市浦东区世纪大道</td>
        </tr>
    </table>
</div>
<script>
    $(function () {
        getOrderDetail();
    })

    function getOrderDetail() {
        // 获取到订单ID
        var orderId = g_getQueryString("orderId");

        $.ajax({
            url: '/order/detail',
            method: 'GET',
            data: {
                orderId: orderId
            },
            success: function (data) {
                if (data.code === 200) {
                    // 渲染订单详情数据
                    render(data.data);
                } else {
                    if (data.code === 500213) {
                        // 用户未登录则重定向到登录页面
                        layer.msg(data.message, function () {
                            window.location.href = "/login/toLogin";
                        })
                    } else {
                        layer.msg(data.message);
                    }

                }
            },
            error: function () {
                layer.msg("订单信息获取失败");
            }
        })
    }

    /**
     * 渲染数据
     *
     * @param detail
     */
    function render(detail) {
        var goods = detail.goodsVO;
        var order = detail.orderVO;

        $("#goodsName").text(goods.goodsName);
        $("#goodsImage").attr("src", goods.goodsImage);
        $("#goodsPrice").text(goods.goodsPrice);
        $("#createTime").text(goods.createTime);
        var status = order.status;
        var statusText = "";

        switch (status) {
            case 0: statusText = "未支付"; break;
            case 1: statusText = "待发货"; break;
            case 2: statusText = "已发货"; break;
            case 3: statusText = "已收货"; break;
            case 4: statusText = "已退款"; break;
            case 5: statusText = "已完成"; break;
        }
        $("#status").text(statusText);
    }
</script>
</body>
</html>>